<?php
/**
 * Created by PhpStorm.
 * User: cxj
 * Date: 16/12/23
 * Time: 下午4:15
 */
namespace app\controllers;

use yii\web\Controller;
use app\models\Poster;

class HomeController extends  Controller{
    public function actionIndex(){
        $view = \Yii::$app->view;
        $view->params['menuItem']=1;
        $poster=new Poster();
        $rs=$poster->getAllPoster();
        $total=count($rs);
        $pageSize=ceil($total/2);
        $posterContent=array_slice($rs,0,2);
//        var_dump($posterContent);
//        var_dump($total);
//        var_dump($pageSize);
//
//        exit();
//        $total=Poster::find()->where(['del_flag' => 1])->asArray()->all();
//        $total = count($total);
//        $total = json_encode($total);
//        $pageSize = ceil($total/2);
//        var_dump($pageSize);
        return $this->render('index', [
            'total' => $total,
            'pageSize' => $pageSize,
            'posterContent'=>$posterContent
        ]);
    }


    public function actionGetPoster(){
        $request=\Yii::$app->request;
        $pageNum=$request->get('pageNum');
        $poster=new Poster();
        $rs=$poster->getAllPoster();
        $res=$poster->getPosterByPageNum($rs,$pageNum);
        echo json_encode($res);



    }

}